const area = require("./area_code_2024.json");

const fs = require("fs");
const arr = [];
function handlerTrees(trees) {
  trees.forEach((ele) => {
    if (ele.children) {
      handlerTrees(ele.children);
      arr.push(ele);
    } else {
      arr.push(ele);
    }
  });
}

handlerTrees(area);

const newArr = arr.map((ele) => {
  return {
    code: ele.code,
    name: ele.name,
    level: ele.level,
    pCode: ele.pcode,
  };
});

fs.writeFileSync("./new_area_code_2024.json", JSON.stringify(newArr));
